This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.
library(ggplot2)
p=ggplot(diamonds)
p+geom_histogram(aes(x=price))
p2=ggplot(diamonds,aes(x=price))
p2+geom_histogram()
p2+stat_bin(geom = "area")
p2+stat_bin(geom = "point")
p2+stat_bin(geom = "line")
p2+geom_histogram(aes(fill=clarity))
p2+geom_histogram(aes(y=..density..))
p3=ggplot(diamonds,aes(x=cut,y=price))
p3+geom_boxplot(fill="red")+coord_flip()
p3+geom_violin()+stat_summary(fun.y="median",geom="point")
p3+geom_jitter()
p3=ggplot(diamonds,aes(x=carat,y=price))
p3+geom_line()+facet_wrap(~cut,ncol = 2)
#install.packages("ggrepel")
library(ggrepel)
state.abb
[1] "AL" "AK" "AZ" "AR" "CA" "CO" "CT" "DE" "FL" "GA"
[11] "HI" "ID" "IL" "IN" "IA" "KS" "KY" "LA" "ME" "MD"
[21] "MA" "MI" "MN" "MS" "MO" "MT" "NE" "NV" "NH" "NJ"
[31] "NM" "NY" "NC" "ND" "OH" "OK" "OR" "PA" "RI" "SC"
[41] "SD" "TN" "TX" "UT" "VT" "VA" "WA" "WV" "WI" "WY"
state.x77
Population Income Illiteracy Life Exp
Alabama 3615 3624 2.1 69.05
Alaska 365 6315 1.5 69.31
Arizona 2212 4530 1.8 70.55
Arkansas 2110 3378 1.9 70.66
California 21198 5114 1.1 71.71
Colorado 2541 4884 0.7 72.06
Connecticut 3100 5348 1.1 72.48
Delaware 579 4809 0.9 70.06
Florida 8277 4815 1.3 70.66
Georgia 4931 4091 2.0 68.54
Hawaii 868 4963 1.9 73.60
Idaho 813 4119 0.6 71.87
Illinois 11197 5107 0.9 70.14
Indiana 5313 4458 0.7 70.88
Iowa 2861 4628 0.5 72.56
Kansas 2280 4669 0.6 72.58
Kentucky 3387 3712 1.6 70.10
Louisiana 3806 3545 2.8 68.76
Maine 1058 3694 0.7 70.39
Maryland 4122 5299 0.9 70.22
Massachusetts 5814 4755 1.1 71.83
Michigan 9111 4751 0.9 70.63
Minnesota 3921 4675 0.6 72.96
Mississippi 2341 3098 2.4 68.09
Missouri 4767 4254 0.8 70.69
Montana 746 4347 0.6 70.56
Nebraska 1544 4508 0.6 72.60
Nevada 590 5149 0.5 69.03
New Hampshire 812 4281 0.7 71.23
New Jersey 7333 5237 1.1 70.93
New Mexico 1144 3601 2.2 70.32
New York 18076 4903 1.4 70.55
North Carolina 5441 3875 1.8 69.21
North Dakota 637 5087 0.8 72.78
Ohio 10735 4561 0.8 70.82
Oklahoma 2715 3983 1.1 71.42
Oregon 2284 4660 0.6 72.13
Pennsylvania 11860 4449 1.0 70.43
Rhode Island 931 4558 1.3 71.90
South Carolina 2816 3635 2.3 67.96
South Dakota 681 4167 0.5 72.08
Tennessee 4173 3821 1.7 70.11
Texas 12237 4188 2.2 70.90
Utah 1203 4022 0.6 72.90
Vermont 472 3907 0.6 71.64
Virginia 4981 4701 1.4 70.08
Washington 3559 4864 0.6 71.72
West Virginia 1799 3617 1.4 69.48
Wisconsin 4589 4468 0.7 72.48
Wyoming 376 4566 0.6 70.29
Murder HS Grad Frost Area
Alabama 15.1 41.3 20 50708
Alaska 11.3 66.7 152 566432
Arizona 7.8 58.1 15 113417
Arkansas 10.1 39.9 65 51945
California 10.3 62.6 20 156361
Colorado 6.8 63.9 166 103766
Connecticut 3.1 56.0 139 4862
Delaware 6.2 54.6 103 1982
Florida 10.7 52.6 11 54090
Georgia 13.9 40.6 60 58073
Hawaii 6.2 61.9 0 6425
Idaho 5.3 59.5 126 82677
Illinois 10.3 52.6 127 55748
Indiana 7.1 52.9 122 36097
Iowa 2.3 59.0 140 55941
Kansas 4.5 59.9 114 81787
Kentucky 10.6 38.5 95 39650
Louisiana 13.2 42.2 12 44930
Maine 2.7 54.7 161 30920
Maryland 8.5 52.3 101 9891
Massachusetts 3.3 58.5 103 7826
Michigan 11.1 52.8 125 56817
Minnesota 2.3 57.6 160 79289
Mississippi 12.5 41.0 50 47296
Missouri 9.3 48.8 108 68995
Montana 5.0 59.2 155 145587
Nebraska 2.9 59.3 139 76483
Nevada 11.5 65.2 188 109889
New Hampshire 3.3 57.6 174 9027
New Jersey 5.2 52.5 115 7521
New Mexico 9.7 55.2 120 121412
New York 10.9 52.7 82 47831
North Carolina 11.1 38.5 80 48798
North Dakota 1.4 50.3 186 69273
Ohio 7.4 53.2 124 40975
Oklahoma 6.4 51.6 82 68782
Oregon 4.2 60.0 44 96184
Pennsylvania 6.1 50.2 126 44966
Rhode Island 2.4 46.4 127 1049
South Carolina 11.6 37.8 65 30225
South Dakota 1.7 53.3 172 75955
Tennessee 11.0 41.8 70 41328
Texas 12.2 47.4 35 262134
Utah 4.5 67.3 137 82096
Vermont 5.5 57.1 168 9267
Virginia 9.5 47.8 85 39780
Washington 4.3 63.5 32 66570
West Virginia 6.7 41.6 100 24070
Wisconsin 3.0 54.5 149 54464
Wyoming 6.9 62.9 173 97203
stateinfo=data.frame(state.abb,state.x77)
stateinfo
p4=ggplot(stateinfo,aes(x=Population,y=Income))
p4+geom_point()
p4+geom_point()+geom_text(aes(label=state.abb),size=3)
p4+geom_point()+geom_text_repel(aes(label=state.abb),size=3)
p5=p4+geom_point(aes(text=paste("state:",state.abb,"murder:",Murder)))
Ignoring unknown aesthetics: text
library(plotly)
ggplotly(p5)
We recommend that you use the dev version of ggplot2 with `ggplotly()`
Install it with: `devtools::install_github('hadley/ggplot2')`